import { _decorator, Component, Node, Button } from 'cc';
import { BundleMgr } from "./frame/mgr/BundleMgr";
import { ConfigMgr } from "./frame/mgr/ConfigMgr";
import { EventMgr } from "./frame/mgr/EventMgr";
import { GameLogic } from "./frame/mgr/GameLogic";
import { IMgr } from "./frame/mgr/IMgr";
import { LoadingMgr } from "./frame/mgr/LoadingMgr";
import { ModuleMgr } from "./frame/mgr/ModuleMgr";
import { ResMgr } from "./frame/mgr/ResMgr";
import { TimerMgr } from "./frame/mgr/TimerMgr";
import { ViewMgr } from "./frame/mgr/ViewMgr";
const { ccclass, property } = _decorator;

@ccclass('App')
export class App {

    private static _ins: App;
    static get ins(): App {
        if (!this._ins) {
            this._ins = new App();
        }
        return this._ins;
    }

    gameLogic: GameLogic = new GameLogic();

    viewMgr: ViewMgr = new ViewMgr();
    bundleMgr: BundleMgr = new BundleMgr();
    eventMgr: EventMgr = new EventMgr();
    timerMgr: TimerMgr = new TimerMgr();
    resMgr: ResMgr = new ResMgr();
    configMgr: ConfigMgr = new ConfigMgr();
    moduleMgr: ModuleMgr = new ModuleMgr();

    loadingMgr: LoadingMgr = new LoadingMgr(this.gameLogic);

    mgrArr: IMgr[] = [
        this.viewMgr,
        this.bundleMgr,
        this.eventMgr,
        this.timerMgr,
        this.resMgr,
        this.configMgr,
        this.moduleMgr,
    ]

    init(): void {
        const arr = this.mgrArr;

        for (const r of arr) {
            r.init();
        }

        this.loadingMgr.init();


    }

    finit(): void {
        const arr = this.mgrArr;

        for (const r of arr) {
            r.finit();
        }
    }

    start(): void {
        this.loadingMgr.startLoading();
    }
}